package mi.payment.ui.director;

import android.os.Bundle;
import android.view.View;
import android.widget.CompoundButton;
import mi.payment.R;
import mi.payment.settings.TransactionSwitchSetting;
import mi.payment.settings.TransactionSwitchOperation;
import mi.payment.transaction.AutoFinishActivity;
import sunmi.sunmiui.button.ButtonSwitch;
import sunmi.sunmiui.title.Title;

/**
 * 自动登录管理界面
 * Created by zdy on 2017/7/20.
 */

public class OperatorAdminAutoLogin extends AutoFinishActivity {
    private ButtonSwitch set_switch;

    private TransactionSwitchOperation transactionSwitchOperation;
    private TransactionSwitchSetting transactionSwitchSetting;
    private boolean autoLogin = true;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_auto_login_manage);
        setStatusBarColor(getResources().getColor(R.color.colorBar));
        setAutoFinish(false);
        initView();
        transactionSwitchOperation = TransactionSwitchOperation.getInstance();
        transactionSwitchSetting = transactionSwitchOperation.getTransactionSwitchSetting();
        autoLogin = transactionSwitchSetting.isAutoChecked();
        set_switch.setOnCheck(autoLogin);

    }


    private void initView() {
        Title mTitle = (Title) findViewById(R.id.title_auto_login_manage);
        mTitle.setButtonVisibility(false, true, true, true);
        mTitle.setHeadBgColor(getResources().getColor(R.color.colorBar));
        mTitle.setTitleText(getResources().getString(R.string.auto_Login_Manage));
        mTitle.setMenuClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                OperatorAdminAutoLogin.this.finish();
            }
        }, null, null, null);

        set_switch = (ButtonSwitch) findViewById(R.id.btn_open_auto_login);
        set_switch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {

                transactionSwitchOperation.saveAutoCheckIn(isChecked);
//                autoLogin = isChecked;
            }
        });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();

    }
}
